package part12;

/**
 * @author wcj
 * @Date 2021/5/21 14:51
 * @Version 1.0
 */
public class Part122 {

    public static void f() throws MyException {
        System.out.println("throw MyException from f()");
        throw new MyException();
    }

    public static void g() throws MyException {
        System.out.println("throw MyException from g()");
        throw new MyException("parameter String");
    }

    public static void main(String[] args) {
        Part122 part122 = new Part122();
        try {
            f();
        } catch (MyException e) {
            // 默认输出到标准错误流中
            e.printStackTrace();
        }

        try {
            g();
        } catch (MyException e) {
            e.printStackTrace(System.out);
        }
    }
}

/**
 * 自定义有参构造器的异常类
 */
class MyException extends Exception {
    public MyException() {
    }

    public MyException(String message) {
        super(message);
    }
}
